<?php
// +----------------------------------------------------------------------
// | Quotes [ 只为给用户更好的体验]**[我知道发出来有人会盗用,但请您留版权]
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 青涩  <3489621943@qq.com>          盗用不留版权,你就不配拿去!
// +----------------------------------------------------------------------
// | Date: 2021年03月24日
// +----------------------------------------------------------------------

include("../includes/common.php");
$title='账号列表';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
<style>
td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:300px;}
.form-inline .form-control {
    display: inline-block;
    width: auto;
    vertical-align: middle;
}
.form-inline .form-group {
    display: inline-block;
    margin-bottom: 0;
    vertical-align: middle;
}
</style>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>账号列表</title>
<link href="../assets/css/bootstrap.min.css" rel="stylesheet">
<link href="../assets/css/materialdesignicons.min.css" rel="stylesheet">
<link href="../assets/css/style.min.css" rel="stylesheet">
</head>
<?php

$my=isset($_GET['my'])?$_GET['my']:null;

if($my=='search' && !empty($_GET['appid'])) {
	$appid = intval($_GET['appid']);
	$sql=" `appid`='$appid'";
	if(!empty($_GET['type']) && $_GET['type']!='0'){
		$type = $_GET['type'];
		$sql.=" AND `type`='$type'";
		if(!empty($_GET['openid'])){
			$openid = trim($_GET['openid']);
			$sql.=" AND `openid`='$openid'";
		}
	}
	$numrows=$DB->getColumn("SELECT count(*) from ucenter_accounts WHERE{$sql}");
	$con='APPID:'.$appid.' 共有 <b>'.$numrows.'</b> 个账号';
	$link="&appid=".$appid;
	if(!empty($_GET['type']) && $_GET['type']!='0'){
		$link.="&type=".$type;
		if(!empty($_GET['openid'])){
			$con='APPID:'.$appid.' openid:'.$openid.' 共有 <b>'.$numrows.'</b> 个账号';
			$link.="&openid=".$openid;
		}
	}
}else{
	$numrows=$DB->getColumn("SELECT count(*) from ucenter_accounts WHERE 1");
	$sql=" 1";
	$con='系统共有 <b>'.$numrows.'</b> 个账号';
}

echo '<div class="container-fluid p-t-15">
  
  <div class="row">
    
    <div class="col-lg-6">
      <div class="card">
        <header class="card-header"><div class="card-title">应用列表</div></header>
        <div class="card-body"><form action="account.php" method="GET" class="form-inline"><input type="hidden" name="my" value="search">
  <div class="form-group">
    <label>搜索</label>
    <input type="text" class="form-control" name="appid" placeholder="APPID" value="'.$_GET['appid'].'">
  </div>
  <div class="form-group">
	<select name="type" class="form-control" default="'.$_GET['type'].'"><option value="0">所有登录方式</option><option value="qq">QQ</option><option value="wx">微信</option><option value="alipay">支付宝</option><option value="baidu">百度</option><option value="sina">新浪微博</option></select>
  </div>
  <div class="form-group">
	<input type="text" class="form-control" name="openid" placeholder="第三方账号UID" value="'.$_GET['openid'].'">
  </div>
  <button type="submit" class="btn btn-primary">搜索</button>&nbsp;<a href="./account.php" class="btn btn-default">重置</a>
</form>';
echo $con;
?>
      <div class="table-responsive">
        <table class="table table-striped">
          <thead><tr><th>ID</th><th>APPID</th><th>方式</th><th>第三方账号UID</th><th>昵称</th><th>头像</th><th>所在地</th><th>性别</th><th>登录IP</th><th>最后登录时间</th><th>操作</th></tr></thead>
          <tbody>
<?php
$pagesize=30;
$pages=ceil($numrows/$pagesize);
$page=isset($_GET['page'])?intval($_GET['page']):1;
$offset=$pagesize*($page - 1);

$rs=$DB->query("SELECT * FROM ucenter_accounts WHERE{$sql} order by id desc limit $offset,$pagesize");
while($res = $rs->fetch())
{
echo '<tr><td><b>'.$res['id'].'</b></td><td><a href="./list.php?my=search&column=appid&value='.$res['appid'].'" target="_blank">'.$res['appid'].'</a></td><td>'.$res['type'].'</td><td>'.$res['openid'].'</td><td>'.$res['nickname'].'</td><td>'.($res['faceimg']?'<a href="'.$res['faceimg'].'" target="_blank" rel="noreferrer">[查看]</a>':null).'</td><td>'.$res['location'].'</td><td>'.$res['gender'].'</td><td><a href="https://m.ip138.com/iplookup.asp?ip='.$res['ip'].'" target="_blank" rel="noreferrer">'.$res['ip'].'</a></td><td>'.$res['lasttime'].'</td><td><a href="./edit.php?my=del_account&id='.$res['id'].'" class="btn btn-xs btn-danger" onclick="return confirm(\'你确实要删除此记录吗？\');">删除</a>&nbsp;<a href="./log.php?my=search&appid='.$res['appid'].'&type='.$res['type'].'&openid='.$res['openid'].'" class="btn btn-xs btn-default">日志</a></td></tr>';
}
?>
          </tbody>
        </table>
      </div>
<?php
echo'<ul class="pagination">';
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo '<li><a href="account.php?page='.$first.$link.'">首页</a></li>';
echo '<li><a href="account.php?page='.$prev.$link.'">&laquo;</a></li>';
} else {
echo '<li class="disabled"><a>首页</a></li>';
echo '<li class="disabled"><a>&laquo;</a></li>';
}
$start=$page-10>1?$page-10:1;
$end=$page+10<$pages?$page+10:$pages;
for ($i=$start;$i<$page;$i++)
echo '<li><a href="account.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '<li class="disabled"><a>'.$page.'</a></li>';
for ($i=$page+1;$i<=$end;$i++)
echo '<li><a href="account.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '';
if ($page<$pages)
{
echo '<li><a href="account.php?page='.$next.$link.'">&raquo;</a></li>';
echo '<li><a href="account.php?page='.$last.$link.'">尾页</a></li>';
} else {
echo '<li class="disabled"><a>&raquo;</a></li>';
echo '<li class="disabled"><a>尾页</a></li>';
}
echo'</ul>';
#分页
?>
    </div>
  </div>
<script>
var items = $("select[default]");
for (i = 0; i < items.length; i++) {
	$(items[i]).val($(items[i]).attr("default")||0);
}
</script>
  <script type="text/javascript" src="../assets/js/jquery.min.js"></script>
<script type="text/javascript" src="../assets/js/popper.min.js"></script>
<script type="text/javascript" src="../assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../assets/js/main.min.js"></script>
</body>
</html>